<?php
/**
 * DB_Shard_Table
 *
 * 作者: 谷明启(gumingqi@comsenz.com)
 * 创建时间: 2011-04-18 18:30:12
 * 修改记录:
 *
 * $Id$
 */
class DB_Shard_Table extends DB_Shard {

    /**
     * 此分库规则下的数据库配置信息
     * 
     */
    private $_db = array();

    /**
     * 分库的关键字
     * 此变量暂时不用
     * @var array
     */
    private $_shardKey;

    /**
     * 传入的数据库配置信息
     * 
     * @var array
     */
    private $_options;

    public function __construct($options, $shardKey = array()) {

        $this->_options = $options;

        // 此变量暂时未用到
        $this->_shardKey = $shardKey;

        $this->shard($options['config'], $shardKey);
    }

    /**
     * shard
     * 分片处理，获取传入的数据库配置
     *
     * @param  array $shards
     * @param  array $shardKey
     * @return boolean
     */
    protected function shard($shards, $shardKey = array()) {

        try {
            $this->_db['dsn'] = $shards['dsn'];
            $this->_db['user'] = $shards['user'];
            $this->_db['password'] = $shards['password'];
            $this->_db['charset'] = $shards['charset'];
            $this->_db['persistent'] = $shards['persistent'];

        } catch (Exception $e) {
            throw new Yaf_Exception($e);
        }

        return true;
    }

    /**
     * getDB
     * 获取数据库配置
     *
     * @return array
     */
    public function getDB() {

        return  $this->_db;
    }
}
